package cn.yudao.system.service.impl;

import cn.yudao.basic.query.BaseQuery;
import cn.yudao.basic.service.impl.BaseServiceImpl;
import cn.yudao.basic.utils.PageList;
import cn.yudao.system.domain.SystemDetail;
import cn.yudao.system.mapper.SystemDetailMapper;
import cn.yudao.system.mapper.SystemTypeMapper;
import cn.yudao.system.query.SystemDetailQuery;
import cn.yudao.system.service.ISystemDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SystemDetailServiceImpl extends BaseServiceImpl<SystemDetail> implements ISystemDetailService {

    @Autowired
    private SystemDetailMapper mapper;

    @Autowired
    private SystemTypeMapper mapper1;

    @Override
    public void save(SystemDetail systemDetail) {

//        System.out.println(systemDetail);
//        if (systemDetail.getSystemType().getName() != null){
//            System.out.println(systemDetail);
//            Long s = mapper1.ById(systemDetail.getSystemType().getName());
//            System.out.println(s);
//            if (s==null){
//                System.out.println(0/0);
//            }
//            systemDetail.setTypes_id(s);
//        }
        mapper.save(systemDetail);
    }

    @Override
    public void upadte(SystemDetail systemDetail) {
//        if (systemDetail.getSystemType().getName() != null){
//            System.out.println(systemDetail);
//            Long s = mapper1.ById(systemDetail.getSystemType().getName());
//            systemDetail.setTypes_id(s);
//        }
        mapper.upadte(systemDetail);
    }

    @Override
    public PageList<SystemDetail> query(BaseQuery baseQuery) {
        // 查询当前页数据
        List<SystemDetail> rows = mapper.query(baseQuery);
        System.out.println(rows);

        // 查询当前页条数
        Integer total = mapper.pagecount(baseQuery);
        System.out.println("这儿" + total);

        return new PageList<SystemDetail>(total, rows);
    }

}
